<?php
require_once dirname ( __FILE__ ) . '/../../bootstrap/unit.php';

class unit_OrganizationalUnitTest extends WildlivePHPUnitTestCase {

  public function testPropertyExistingOrgUnitChairman() {
    $unit = $this->getStammSilvaAboba();
    
    $property = $unit->getPropertyValue('org_unit_chairman');
    $this->assertInstanceOf('AbstractOrganizationalProperty', $property);
    //$this->assertInstanceOf('MemberOrganizationalProperty', $property);
    
    $value = $property->getValue();
    $this->assertInternalType('string', $value);
    $this->assertEquals(205, $value, 'Check fixtures');
  }

  public function testPropertyNotExistingOrgUnitDeputyChairman ()
  {
    $unit = $this->getStammSilvaAboba();
    
    $property = $unit->getPropertyValue('org_unit_deputy_chairman');
    $this->assertInstanceOf('AbstractOrganizationalProperty', $property);
    //$this->assertInstanceOf('MemberOrganizationalProperty', $property);
    

    $value = $property->getValue();
    $this->assertNull($value);
  }

  public function testPropertyExistingOrgUnitTreasurer ()
  {
    $unit = $this->getStammSilvaAboba();
    
    $property = $unit->getPropertyValue('org_unit_treasurer');
    $this->assertInstanceOf('AbstractOrganizationalProperty', $property);
    //$this->assertInstanceOf('MemberOrganizationalProperty', $property);
    

    $value = $property->getValue();
    $this->assertInternalType('string', $value);
    $this->assertEquals(64, $value, 'Check fixtures');
  }
  
  
  /**
   * @return OrganizationalUnit
   */
  private function getStammSilvaAboba() {
    $unit = OrganizationalUnitTable::getInstance()->findOneByName('Stamm Silva Abnoba');
    $this->assertInstanceOf('OrganizationalUnit', $unit, 'Check fixtures');
    return $unit;
  }
public function test() {}
//  private function loadFixtureSet001() {
//    $this->loadFixtures ( 'organizational_unit.yml','organizational_entity.yml', 'organizational_property_type.yml', 'organizational_property.yml', 'organizational_entity_property_assignment.yml', 'organizational_unit_property_assignment.yml' );
//  }
//  
//  /**
//   * @return OrganizationalUnit
//   */
//  private function getRedChapter() {
//    return OrganizationalUnitTable::getInstance()->findOneByName('Stamm Rot');
//  }
//  
//  /**
//   * @return OrganizationalUnit
//   */
//  private function getBlueChapter() {
//    return OrganizationalUnitTable::getInstance()->findOneByName('Stamm Blau');
//  }
//  
//  public function testGetPropertyValueShouldPreferUnitPropertiesOverEntityProperties() {
//    $this->loadFixtureSet001();
//    
//    // Chapter with can_have_members := 0
//    $chapter = $this->getBlueChapter();
//    $this->assertEquals(0, $chapter->getPropertyValue('can_have_members'));
//    
//    // Chapter with can_have_members := 1
//    $chapter = $this->getRedChapter();
//    $this->assertEquals(1, $chapter->getPropertyValue('can_have_members'));
//  }
//  
//  public function testGetPropertyValueShouldReturnNullForInvalidProperty() {
//    $this->loadFixtureSet001();
//    
//    $chapter = $this->getBlueChapter();
//    $this->assertNull($chapter->getPropertyValue('some_random_invalid_property'));
//  }
//  
//  public function testGetPropertyValuesShouldReturnArrayOfAllOrganizationalPropertyAssignmentAggregationInstances() {
//    $this->loadFixtureSet001();
//    
//    $chapter = $this->getBlueChapter();
//    $properties = $chapter->getPropertyValues();
//    $this->assertTrue(is_array($properties));
//  }
}